import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'

import Vant from 'vant'
import './plugins/rem'
import {
	Toast,
	Dialog
} from 'vant'
import 'vant/lib/index.css'

Vue.config.productionTip = false
Vue.prototype.$axios = axios

Vue.prototype.$img = 'http://www.xjyfb.com'
Vue.prototype.$url = 'http://api.xjyfb.com'
require('./assets/css/reset.css')
require('./assets/css/base.css')
require('./assets/css/quill.core.css')
Vue.use(Vant);
//跳转路由
Vue.prototype.$loading = () => {
	Toast.loading({
		duration: 0,
		message: '加载中...',
		forbidClick: true,
		loadingType: 'spinner'
	});
};
//****
Vue.prototype.$phone = (val) => {
	if (!val||val.lengt<10) {
		return val
	}
	let phone = String(val).split('');
	let start = phone.splice(0, 3).join('');
	let end = phone.splice(-3, 3).join('');
	return start + '****' + end;
};
//验证手机号
Vue.prototype.$yzPhone = (value) => {
	if (value == '') {
		Toast('请输入手机号码');
		return true
	}
	if (!/^1[3456789]\d{9}$/.test(value)) {
		Toast('请输入正确格式手机号码');
		return true
	} else {
		return false
	}
};
//验证邮箱
Vue.prototype.$yzEmail = (value) => {
	if (value == '') {
		Toast('请输入邮箱');
		return true
	}
	if (!/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/.test(value)) {
		Toast('请输入正确格式邮箱');
		return true
	} else {
		return false
	}
};
Vue.prototype.$newText = (val) => {
	if (!val) {
		return ''
	}
	let notice = '',
		arr = [];
	arr = val.split('<img');
	arr.forEach((item, index) => {
		if (index) {
			notice = notice + "<img style='width:100%;height:100%'" + item;
		} else {
			notice = item;
		}
	});
	return notice
}
Vue.prototype.$ip = (callback) => {
	axios.get('https://restapi.amap.com/v3/ip?output=xml&key=d8e4057395b81ef19a6f2a859518a971').then(res=>{
    console.log(res.data);
    let arr = res.data.split('<province>')[1].split('</province>');
    callback(arr[0])
  }).catch(err=>{
    console.log(err)
  })
}
//时间戳转化成时间
Vue.prototype.$IsPC = () => {
	var userAgentInfo = navigator.userAgent;
	var Agents = ["Android", "iPhone",
	    "SymbianOS", "Windows Phone",
	    "iPad", "iPod"];
	var flag = true;
  for (var v = 0; v < Agents.length; v++) {
	        if (userAgentInfo.indexOf(Agents[v]) > 0) {
	            flag = false;
	        }
	    }
  if(flag){
    window.location.href="http://www.xjyfb.com/"
  }
};
export default new Vue({
	store,
	router,
	render: h => h(App),
}).$mount('#app')
